//平衡二叉树
class Solution {
public:
    bool isBalanced(TreeNode* root) 
    {
        //要想判断是不是平衡二叉树 就要看他的左子树和右子树的高度
        //实现一个函数获得左子树和右子树的高度
        if(!root) return true;
        int left=gethigh(root->left);
        int right=gethigh(root->right);
        return abs(left-right)<2&&isBalanced(root->left) && isBalanced(root->right);
    }
    int gethigh(TreeNode* root)
    {
        if(!root) return 0;
        return 1+max(gethigh(root->left),gethigh(root->right));
    }
};
//二叉树的所有路径
class Solution {
public:
    //回溯
    vector<int> path;
    vector<string> res;
    vector<string> binaryTreePaths(TreeNode* root) 
    {
        if(!root) return res;
        dfs(root);
        return res;
    }
    void dfs(TreeNode* root)
    {
        path.push_back(root->val);
        //结束条件
        if(!root->left && !root->right)
        {
            string str="";
            for(int i=0;i<path.size()-1;i++)
            {
                str+=to_string(path[i]);
                str+="->";
            }
            str+=to_string(path[path.size()-1]);
            res.push_back(str);
            return;
        }
        if(root->left)
        {
            dfs(root->left);
            path.pop_back();
        }
        if(root->right)
        {
            dfs(root->right);
            path.pop_back();
        }
    }

};